package pers.dzk.fivelnarow.ending;

import pers.dzk.fivelnarow.config.MainWindowConfig;
import pers.dzk.fivelnarow.config.util.ResourcesPath;
import pers.dzk.fivelnarow.window.GameState;
import pers.dzk.fivelnarow.window.MainWindow;
import javax.sound.sampled.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
/**
 * @author 丁泽凯
 */
public class Ending implements IEnding {
    public Ending(){

    }
    @Override
    public void paintEnding(Graphics2D g2d){
        if(MainWindow.getJudge().isOver()){
            g2d.setColor(Color.orange);
            g2d.setFont(new Font("",Font.BOLD,120));
            int x = MainWindowConfig.getWidth()/2-280;
            String str = "游 戏 结 束";
            if(MainWindow.getJudge().getFailPlayer() == null && MainWindow.getJudge().getVictoryPlayer() == null){
                str = "平 局";
                x+=120;
            }else {
//                try {
//                    Clip end = AudioSystem.getClip();
//                    File file = new File(ResourcesPath.AUDIO_PATH +"/end.wav");
//                    AudioInputStream ais = AudioSystem.getAudioInputStream(file);
//                    end.open(ais);
//                    end.start();
//                } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
//                    throw new RuntimeException(e);
//                }
            }

//            g2d.drawString(str,x , MainWindowConfig.getHeight()/2);

        }
    }

    @Override
    public void handle() {
        if(MainWindow.getJudge().isOver()){
            MainWindow.getJudge().setGameState(GameState.结束);
        }
    }



}
